using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class JobSeekers_coverletter : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
             WebConfigurationManager.ConnectionStrings[
               "RecruitVietnam"].ConnectionString;
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            string letterID = 
            Request.QueryString.Get("LetterID");
            if (!IsPostBack)
                EditCoverLetter(letterID);
        }
    }
    void EditCoverLetter(string letterID)
    {
        if (letterID != "" && letterID !=null )
        {
            SqlServerProvider cls = new 
            SqlServerProvider(connectionString);
            cls.CommandText = 
            "select * from tblJSCoverLetters " +
            " where UserID=@UserID" + 
             " and LetterID=@LetterID";
            cls.ParameterCollection = new 
            string[2] { "@LetterID", "@UserID"};
            cls.ValueCollection = new 
            string[2]{ letterID, 
            Session["jsuserid"].ToString()};
            DataRow dataRow =
            cls.GetDataRow();
            LetterID.Value = dataRow[0].ToString();
            txtSubject.Text = dataRow[2].ToString();
            txtBody.Text = dataRow[3].ToString();            
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string id = "0";
        if (LetterID.Value != "")
            id = LetterID.Value;

        RecruitVietnam cls = new RecruitVietnam();
        cls.ConnectionString = connectionString;
        if (!cls.AddNewOrUpdateCoverLetter(id,
        Convert.ToString(Session.Contents["jsuserid"]),
        txtSubject.Text,txtBody.Text))
            literalError.Text = "Error: " + cls.ErrorMessage;
        else
            Response.Redirect("coverletters.aspx");           
    }
}
